﻿// Example header text. Can be configured in the options.
using System;
using System.Data;
using System.Data.SqlClient;
using vtech_frameWorks.DAO;
using vtech_frameWorks.Exceptions;
using vtech_frameWorks.Object;

namespace vtech_system.SystemLog
{
    public class ClsSystemLogDAO : ClsObjectDAO
    {
        public override void Delete(SqlTransaction sqlTransaction, DataRow dataRow)
        {
            try
            {
                SqlParameter[] paramArray = new SqlParameter[]
                {
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@ID", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input),
                };
                ClsBaseDbAccessDAO.SetParameterValues(paramArray, dataRow);
                ClsBaseDbAccessDAO.ExecuteNonQuery(sqlTransaction, "spDeleteSystemLog", paramArray);
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.Message);
                return;
            }
        }

        public override DataTable GetAll(SqlTransaction sqlTransaction)
        {
            try
            {
                return ClsBaseDbAccessDAO.ExecuteSqlDataAdapter(sqlTransaction, "spGetSystemLog").Tables[0];
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
                return null;
            }
        }

        public override void Insert(SqlTransaction sqlTran, DataRow dRow)
        {
            try
            {
                SqlParameter[] paramArray = new SqlParameter[]
                {
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@ID", SqlDbType.UniqueIdentifier, -1, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@NamePC", SqlDbType.NVarChar, 200, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Username", SqlDbType.NVarChar, 50, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Created", SqlDbType.DateTime, -1, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Module", SqlDbType.NVarChar, 255, ParameterDirection.Input)
                };
                ClsBaseDbAccessDAO.SetParameterValues(paramArray, dRow);
                ClsBaseDbAccessDAO.ExecuteProcedure(sqlTran, "spAddSystemLog", paramArray);
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
                return;
            }
        }
    }
}